1. /* snmcopyv.cpp by K.Tsuru */
  2. // function ID = 104
  3. /****************************************************************
  4. SNumber class
  5. It copies various values, FigBlock figure,etc.
  6. If cs = COPY, it sets figure = a.figure only.This is used in the copy
  7. constructor of te derived class.
  8. If cs = SUBS, it allocates memory or adjusts the size of figure.
  9. This is used in the substitution operators.
  10. *****************************************************************/
  11. #ifndef SN_H
  12. #include "sn.h"
  13. #endif
  14. #ifndef NDEBUG
  15. static const char* func = "CopyValue";
  16. #endif
  17. void SNumber::CopyValue(const SNumber& a, int cs)
  18. {
  19. if(this == &a) return; //For a = a.
  20. aHead = a.aHead; aTail = a.aTail; type = a.type;
  21. // Called by copy constructor.
  22. if(cs == COPY){
  23. figure = a.figure;
  24. #ifndef NDEBUG
  25. assert(figure.Error() == figure.NORMAL);
  26. #endif
  27. sign = a.sign;
  28. return;
  29. }
  30. if(a.sign == ZERO){ // a = 0; It may be able to minimize the size.
  31. //If Sign() is used UNDEC_VALUE error occures.
  32. //Do not use figure.size(minArraySize,0); It may be cutDown == DISABLE.
  33. SetZero(); return;
  34. }
  35. //It prohibits to substitute an unsubstantial object for a substantial one.
  36. if( (a.figure.size() == 0) || (a.sign == UNDECIDED) ){
  37. if(figure.size() > 0) SetError(UNDEC_VALUE, "", 104);
  38. return; // a.figure.size() = figure.size() = 0 is OK.
  39. }
  40. // sign = a.sign; // Execute in last line.
  41. /********************************************************
  42. When CutDown() == DISABLE, do not reduce the size of this.
  43. See Lpow() function for example.
  44. *********************************************************/
  45. uint alc_sz;
  46. if(CutDown() == DISABLE) alc_sz = max(a.figure.size(), figure.size());
  47. else alc_sz = a.aHead +1;
  48. valloc(alc_sz, -1); //It does not copy and allocates the memory. sign = UNDECIDED;
  49. uint max_sz = SNMaxSize(type), n_copy;
  50. if(type & REAL){ // real type
  51. n_copy = min(figure.size(), a.aHead+1);
  52. //It considers the substitution of longer number e.g. E()
  53. //after reducing the number of effective figures.
  54. if(n_copy > max_sz) n_copy = max_sz;
  55. } else n_copy = a.aHead + 1; // integer type
  56. //It copies the lower part of a.
  57. memcpy(figure.Elements(), a.ReadFigures() , n_copy*sizeof(fType) );
  58. figure.clear(n_copy); //It fills the upper part with zeros. figure[i]=0 for i>aHead
  59. sign = a.sign; // sign : change UNDECIDED to a.sign
  60. if(aHead >= max_sz){//The number of effective figures was reduced by calling SetEffFig().
  61. CheckArray(-104);//It rarely occures.
  62. }
  63. //check errors
  64. #ifndef NDEBUG
  65. int sc = (sign == UNDECIDED) || (sign == ZERO) || (sign == PLUS) || (sign == MINUS);
  66. if(!sc){
  67. SetError(FATAL, func, (int)sign);
  68. }
  69. if(figure.Error() != figure.NORMAL) SetError(FATAL, func, 104);
  70. if( aHead >= figure.size() ) SetError(FATAL, func, (int)aHead);
  71. if( aTail > aHead ){
  72. SetError(FATAL, func, (int)aTail);
  73. }
  74. #endif
  75. }

snmcopyv.cpp : last modifiled at 2017/03/13 14:32:01(2,935 bytes)
created at 2016/04/11 11:36:47
The creation time of this html file is 2017/10/27 10:59:17 (Fri Oct 27 10:59:17 2017).